
import java.util.Comparator;
import java.util.PriorityQueue;

class Student implements Comparable<Student>{
    int age;

    public Student(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}

public class TestDemo {

    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = { 27,15,19,18,28,34,65,49,25,37 };
        testHeap.createHeap(array);
        testHeap.heapSort();
        System.out.println();
    }

    public static void main4(String[] args) {
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(new Student(12));
        priorityQueue.offer(new Student(1));
        System.out.println(priorityQueue);// 默认小根堆
    }

    public static void main3(String[] args) {
        PriorityQueue priorityQueue =
                new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
    }

    public static void main2(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        // 默认小根堆
        queue.offer(12);
        queue.offer(3);
        queue.offer(78);
        int tmp = queue.peek();
        System.out.println(tmp); // 3
        System.out.println(queue.poll());
        System.out.println(queue.poll());
    }

    public static void main1(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = { 27,15,19,18,28,34,65,49,25,37 };
        testHeap.createHeap(array);
        //testHeap.push(50);
        testHeap.pollHeap();
        System.out.println(array);
    }
}
